<?php
namespace app\decorate\controller;
use app\AdminRest;
use app\ApiRest;
use think\App;
use think\Request;
use app\decorate\model\AdminAppointment as app_model;

class IndexAppointment extends ApiRest{
    protected $model;
    public function __construct(App $app) {
        parent::__construct($app);
        $this->model = new app_model();
    }

    /**
     * User: chenniang
     * Date: 2019-10-09 15:58
     * @return \think\Response
     * descption:预约首页
     */
    public function appIndex(){
//        $time  = strtotime(date('Y-m-d',time()));
//        $times = $time+86400;
//        $dis[] = ['uniacid','=',$this->_uniacid];
//        $dis[] = ['create_time','between',"$time,$times"];
//        $data['count'] = $this->model->appCount($dis);
        $site  = lbPulgSettingInfo($this->_uniacid,'decorate',['app_img','app_num','app_title']);

        $data['count']       = is_numeric($site['app_num'])?$site['app_num']:0;

        $data['img']         = $site['app_img']?$site['app_img']:"";

        $data['app_title']   = $site['app_title']?$site['app_title']:"";
        return $this->success($data);
    }
    /**
     * User: chenniang
     * Date: 2019-10-09 15:58
     * @return \think\Response
     * descption:添加预约
     */
    public function appAdd(){
        $input = $this->_input;
        $input['uniacid'] = $this->_uniacid;
        $input['user_id'] = $this->getUserId();
        $res  = $this->model->appAdd($input);
        $site = lbPulgSettingInfo($this->_uniacid,'decorate',['app_num']);
        $num  = !empty($site['app_num'])?$site['app_num']+1:1;
        $res  = lbPulgSettingUpdate($this->_uniacid,'decorate','app_num',$num);
        return $this->success($res);
    }


}
